package com.gujiayue.common.restful;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.gujiayue.common.utils.ConstantUtils;
import com.gujiayue.common.utils.CoreUtils;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 返回信息
 * @author 胡佳琪
 */
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class RestfulRtnInfo {

	@ApiModelProperty(value = "状态")
	private Boolean status;

	@ApiModelProperty(value = "码")
	private Integer statusCode;

	@ApiModelProperty(value = "消息")
	private String statusReason;

	@ApiModelProperty(value = "对象")
	private Object data;

	@ApiModelProperty(value = "对象注释")
	private Object dataNote;

	public RestfulRtnInfo() {

	}

	/**
	 * 对接接口返回
	 * 
	 * @param code   返回码
	 * @param reason 提示信息
	 */
	public RestfulRtnInfo(Integer code, String reason) {
		this.status = ConstantUtils.STATUS_SUCCESS.equals(code);
		this.statusCode = code;
		this.statusReason = reason;
	}

	/**
	 * 对接接口返回
	 * @param code   返回码
	 * @param reason 提示信息
	 * @param object 返回某个对象
	 */
	public RestfulRtnInfo(Integer code, String reason, Object obj) {
		boolean status=ConstantUtils.STATUS_SUCCESS.equals(code);
		this.dataNote =status?CoreUtils.getInstance().getFieldsNote(obj):null;
		this.status = status;
		this.statusCode = code;
		this.statusReason = reason;
		this.data = obj;
	}
}
